package com.uidt.project.ptsj.service.impl;

import java.util.List;
import com.uidt.common.utils.DateUtils;
import com.uidt.common.utils.SecurityUtils;
import com.uidt.framework.security.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.uidt.project.ptsj.mapper.OfficerMapper;
import com.uidt.project.ptsj.domain.Officer;
import com.uidt.project.ptsj.service.IOfficerService;

/**
 * 部门负责人信息Service业务层处理
 * 
 * @author uidt
 * @date 2024-08-12
 */
@Service
public class OfficerServiceImpl implements IOfficerService 
{
    @Autowired
    private OfficerMapper ptsjOfficerMapper;

    /**
     * 查询部门负责人信息
     * 
     * @param id 部门负责人信息主键
     * @return 部门负责人信息
     */
    @Override
    public Officer selectOfficerById(Long id)
    {
        return ptsjOfficerMapper.selectOfficerById(id);
    }

    /**
     * 查询部门负责人信息列表
     * 
     * @param ptsjOfficer 部门负责人信息
     * @return 部门负责人信息
     */
    @Override
    public List<Officer> selectOfficerList(Officer ptsjOfficer)
    {
        LoginUser user = SecurityUtils.getLoginUser();
        ptsjOfficer.setDeptCode(user.getUser().getDept().getDeptcode().split("-")[0]);
        return ptsjOfficerMapper.selectOfficerList(ptsjOfficer);
    }

    /**
     * 新增部门负责人信息
     * 
     * @param ptsjOfficer 部门负责人信息
     * @return 结果
     */
    @Override
    public int insertOfficer(Officer ptsjOfficer)
    {
        LoginUser user = SecurityUtils.getLoginUser();

        ptsjOfficer.setDeptCode(user.getUser().getDept().getDeptcode());

        return ptsjOfficerMapper.insertOfficer(ptsjOfficer);
    }

    /**
     * 修改部门负责人信息
     * 
     * @param ptsjOfficer 部门负责人信息
     * @return 结果
     */
    @Override
    public int updateOfficer(Officer ptsjOfficer)
    {
        ptsjOfficer.setUpdateTime(DateUtils.getNowDate());
        return ptsjOfficerMapper.updateOfficer(ptsjOfficer);
    }

    /**
     * 批量删除部门负责人信息
     * 
     * @param ids 需要删除的部门负责人信息主键
     * @return 结果
     */
    @Override
    public int deleteOfficerByIds(Long[] ids)
    {
        return ptsjOfficerMapper.deleteOfficerByIds(ids);
    }

    /**
     * 删除部门负责人信息信息
     * 
     * @param id 部门负责人信息主键
     * @return 结果
     */
    @Override
    public int deleteOfficerById(Long id)
    {
        return ptsjOfficerMapper.deleteOfficerById(id);
    }
}
